#include <math.h>

void umbralizar_c (
	unsigned char *src,
	unsigned char *dst,
	int m,
	int n,
	int row_size,
	unsigned char min,
	unsigned char max,
	unsigned char q
) {
	//unsigned char (*src_matrix)[row_size] = (unsigned char (*)[row_size]) src;
	//unsigned char (*dst_matrix)[row_size] = (unsigned char (*)[row_size]) dst;

	int i,j;
  	int actual= 0;
  	for(i= 0; i<m;i++){
		for(j=0; j<n; j++){	

	            actual = (i * row_size) + j;

		    if(src[actual]<min){
			dst[actual]= 0;
		    }else if (src[actual]>max){
		      dst[actual]= 255;
		    }else{
              		float dividendo = src[actual] / q;
              		int i_dividendo = (int) dividendo;
		      	dst[actual]= i_dividendo * q;
		    }
		}
	}
}
